/**
 * 
 */
package mapper;

import java.io.IOException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

/**
 * @author puneet
 *
 */
public class SparseMatrixBuilderMapper extends
		Mapper<LongWritable, Text, LongWritable, Text> {
	
	private static final Log LOG = LogFactory.getLog(SparseMatrixBuilderMapper.class);
	/* (non-Javadoc)
	 * @see org.apache.hadoop.mapreduce.Mapper#map(java.lang.Object, java.lang.Object, org.apache.hadoop.mapreduce.Mapper.Context)
	 */
	@Override
	protected void map(LongWritable key, Text value,Context context)
			throws IOException, InterruptedException {
		int sourceIndex = context.getConfiguration().getInt("sourceIndex", 0);
		int destIndex= context.getConfiguration().getInt("destIndex", 1);
		String[] vals = value.toString().split("\\s");
		String source = vals[sourceIndex];
		String dest = vals[destIndex];
//		
		LOG.error("Source = "+source + "Dest = "+dest);
		context.write(new LongWritable(Long.parseLong(source)), new Text(dest));
		context.write(new LongWritable(Long.parseLong(dest)), new Text(source));
	}

}
